// pages/collect/collect.js
import Dialog from '@vant/weapp/dialog/dialog';
import {
  collectList,
  baseURL,
  cancelCollect
} from "../../api/my"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    collectList: [],
    baseURL,
    userId: wx.getStorageSync("userInfo")["userId"],
    right: 65,
  },
  cancel(event) {
    const id = event.currentTarget.dataset.id;
    wx.showModal({
      title: '系统提示',
      content: '确认取消吗？',
      mask: true,
      complete: async (res) => {
        if (res.confirm) {
          const result = await cancelCollect({
            campId: id,
            userId: this.data.userId
          })
          if (result.code == 200) {
            this.getCollectList()
          }
        }
        if (res.cancel) {
          const that = this
          that.setData({
            right: 0
          })
          setTimeout(()=>{
            that.setData({
              right: 65
            })
          },500)
        }
      }
    })
  },
  goCampDetail(e) {
    //跳转页面+传递参数
    console.log("goCampDetail");
    let campId = e.currentTarget.dataset.campId;
    wx.navigateTo({
      url: `/pages/detail/detail?campId=${campId}`,
    })
  },
  //获取营地列表
  async getCollectList() {
    const result = await collectList({
      userId: this.data.userId
    })
    result.data.map(item => {
      item.imageUrl = item.imageUrl.split(",");
      return item;
    })
    if (result.code == 200) {
      this.setData({
        collectList: result.data
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getCollectList()
  },

})